export default {
  disabledDate(date) {
    const year = new Date().getFullYear();
    const month = new Date().getMonth();
    // 本月以后的月份置灰
    return (
      date.getFullYear() > year ||
      (date.getFullYear() == year && date.getMonth() > month)
    );
  },
  shortcuts: [
    {
      text: "本月",
      onClick(picker) {
        picker.$emit("pick", [new Date(), new Date()]);
      },
    },
    {
      text: "今年至今",
      onClick(picker) {
        const end = new Date();
        const start = new Date(new Date().getFullYear(), 0);
        picker.$emit("pick", [start, end]);
      },
    },
    {
      text: "最近6个月",
      onClick(picker) {
        const end = new Date();
        let start = new Date();

        if (start.getMonth() - 5 > 0) {
          start.setMonth(start.getMonth() - 5);
        } else {
          start = new Date(
            start.getFullYear() - 1,
            12 + start.getMonth() - 5,
            1,
            0,
            0,
            0
          );
        }
        picker.$emit("pick", [start, end]);
      },
    },
    {
      text: "最近12个月",
      onClick(picker) {
        const end = new Date();
        let start = new Date();

        if (start.getMonth() - 11 > 0) {
          start.setMonth(start.getMonth() - 11);
        } else {
          start = new Date(
            start.getFullYear() - 1,
            12 + start.getMonth() - 11,
            1,
            0,
            0,
            0
          );
        }
        picker.$emit("pick", [start, end]);
      },
    },
  ],
};
